/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hwr.nbaplan.server;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


/**
 *
 * @author flo
 */
public class DbConnect {

    private static EntityManagerFactory entityManagerFactory;
    private static EntityManager em;

    /**
     *
     * @param pu
     */
    public static void connect(String pu) {
        entityManagerFactory = Persistence.createEntityManagerFactory(pu);
        em = getEntityManagerFactory().createEntityManager();
    }

    /**
     *
     */
    public static void close(){
        getEm().close();
        getEntityManagerFactory().close();
    }

    /**
     * @return the entityManagerFactory
     */
    public static EntityManagerFactory getEntityManagerFactory() {
        return entityManagerFactory;
    }

    /**
     * @return the em
     */
    public static EntityManager getEm() {
        return em;
    }
}
